package com.neu.controller;

import com.neu.pojo.Floor;
import com.neu.service.FloorService;
import com.neu.service.FloorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
public class FloorController {
    @Autowired
    private FloorService floorService;

    @RequestMapping("delFloor")
    @ResponseBody
    public HashMap delFloor(int floorNum){
        int res=floorService.delFloor(floorNum);
        HashMap<String,Object> map = new HashMap<>();
        if(res>0) {
            map.put("code", 0);
            map.put("msg", "删除成功");
        }else{
            map.put("code", -1);
            map.put("msg", "删除失败，请稍后重试.");
        }
        return map;
    }

    @RequestMapping("updateFloor")
    @ResponseBody
    public HashMap updateFloor(Floor floor){
        int res=floorService.updateFloor(floor);
        HashMap<String,Object> map = new HashMap<>();
        if(res>0) {
            map.put("code", 0);
            map.put("msg", "更新成功");
        }else{
            map.put("code", -1);
            map.put("msg", "更新失败，请稍后重试.");
        }
        return map;
    }


    @RequestMapping("addFloor")
    @ResponseBody
    public HashMap addFloor(Floor floor){
        int res=floorService.addFloor(floor);
        HashMap<String,Object> map = new HashMap<>();
        if(res>0) {
            map.put("code", 0);
            map.put("msg", "新建成功");
        }else{
            map.put("code", -1);
            map.put("msg", "新建失败，请稍后重试.");
        }
        return map;
    }

    @RequestMapping("getFloorByPage")
    @ResponseBody
    public HashMap getFloorByPage(int page,int limit){
        List<Floor> list=floorService.getFloorByPage(page,limit);
        int totalCount=floorService.getFloorCount();
        HashMap<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","success");
        map.put("count",totalCount);
        map.put("data",list);
        return map;
    }


}
